
     /* operadores para opquad */

     #define CPROCEND   1
     #define CPROCBEGIN 2
     #define CATRIB     3
     #define CPARAM     4
     #define CCALL      5
     #define CIGUAL     6
     #define CGOTO      7
     #define CMAIS      8
     #define COU        13
     #define CVEZES     9
     #define CE         14
     #define CMENOS     10
     #define CINVERTE   15
     #define CNEGA      16
     #define CDIV       11
     #define CPOT       12
     #define CDSVF      17
     #define CPROGEND   18
     #define CPROGBEGIN 19


     /* gen */

     typedef struct {
                 int opquad,opn1quad,opn2quad,opn3quad;
              } tquad;


     /* gen */
     int op;
     tquad quad[501];
     FILE *CODE;
     int proxq;
     alfa opnome[20];
     int temps;
     FILE *YYSAIDA;

     void GEN(int operador,int opn1,int opn2,int opn3)
     {
       quad[proxq].opquad   = operador;
       quad[proxq].opn1quad = opn1;
       quad[proxq].opn2quad = opn2;
       quad[proxq].opn3quad = opn3;
       proxq++;
     } /* GEN */

     void CONSERTA(int cond,int addr)
     {
       quad[cond].opn2quad = addr;
     } /* CONSERTA */

     void SALVA(int i,int k)
     {
       int j;
       for (j = i; j <= k; j++)
           fwrite(&quad[j],sizeof(tquad),1,CODE);
     } /* SALVA */

     void MONTAOPNOME(void)
     {
       strcpy(opnome[1 ]," PROCEND      ");
       strcpy(opnome[2 ]," PRCBEGIN     ");
       strcpy(opnome[3 ]," :=           ");
       strcpy(opnome[4 ]," PARAM        ");
       strcpy(opnome[5 ]," CALL         ");
       strcpy(opnome[6 ]," =            ");
       strcpy(opnome[7 ]," GOTO         ");
       strcpy(opnome[8 ]," +            ");
       strcpy(opnome[9 ]," *            ");
       strcpy(opnome[10]," -            ");
       strcpy(opnome[11]," /            ");
       strcpy(opnome[12]," **           ");
       strcpy(opnome[13]," OU           ");
       strcpy(opnome[14]," E            ");
       strcpy(opnome[15]," -            ");
       strcpy(opnome[16]," NEGA         ");
       strcpy(opnome[17]," DSVF         ");
       strcpy(opnome[18]," PROGEND      ");
       strcpy(opnome[19]," PRGBEGIN     ");
     } /* MONTAOPNOME */


     void IMPRIMECODIGO(void)
     {
       int i,j;
       tquad quad;

       MONTAOPNOME();
       fprintf(YYSAIDA,"%4s%s\n"," ", 
            "==========CODIGO GERADO==========");
       fprintf(YYSAIDA,"\n");
       fprintf(YYSAIDA,"%6s%s%2s%s%s%s"," ","opquad"," ","opn1quad ",
            "opn2quad ","opn3quad","\n");
       j = 1;
       while (!feof(CODE))
       {
          fread(&quad,sizeof(tquad),1,CODE);
          fprintf(YYSAIDA,"\n");
          if (!feof(CODE))
          {
          fprintf(YYSAIDA,"%4d%2s%s",j," ",opnome[quad.opquad]);
          switch(quad.opquad)
          {
            case CPROCEND    : { break; }

            case CPROCBEGIN  : {    fprintf(YYSAIDA,"%4s%d"," ",                                    quad.opn1quad);
                             break;
                            }

            case CATRIB      : {    fprintf(YYSAIDA,"%4s%d%6s%d"," ",                               quad.opn1quad," ",quad.opn2quad);
                        break;
                            }

            case CPARAM      : {fprintf(YYSAIDA,"%4s%d"," ",quad.opn1quad);
                        break;
                               }

            case CCALL       : { fprintf(YYSAIDA,"%4s%d"," ",quad.opn1quad);
                        break;
                            }

            case CGOTO       : { fprintf(YYSAIDA,"%12s%d"," ",quad.opn2quad);
                         break;
                            }

            case CMAIS       : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",quad.opn2quad," ",                                quad.opn3quad);
                        break;
                            }

            case COU         : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ", quad.opn2quad," ",                               quad.opn3quad);
                        break;
                         }

            case CIGUAL      : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",quad.opn2quad," ",                                quad.opn3quad);
                        break;
                            }

            case CDIV        : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",quad.opn2quad," ",                                quad.opn3quad);
                        break;
                         }

            case CVEZES      : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",quad.opn2quad," ",                                quad.opn3quad);
                        break;
                            }

            case CE          : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",
                        quad.opn2quad," ",quad.opn3quad);
                        break;
                        }

            case CPOT        : {    fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",
                        quad.opn2quad," ",quad.opn3quad);
                        break;
                          }

            case CMENOS      : {fprintf(YYSAIDA,"%4s%d%6s%d%8s%d"," ",                          quad.opn1quad," ",
                        quad.opn2quad," ",quad.opn3quad);
                        break;
                              }
            case CINVERTE    : {    fprintf(YYSAIDA,"%4s%d%6s%d"," ",                               quad.opn1quad," ",quad.opn2quad);
                            break;
                        }

            case CNEGA       : { fprintf(YYSAIDA,"%4s%d%6s%d"," ",                              quad.opn1quad," ",quad.opn2quad);
                        break;
                             }

            case CDSVF       : {    fprintf(YYSAIDA,"%4s%d%6s%d"," ",                               quad.opn1quad," ",quad.opn2quad);
                        break;
                               }
            case CPROGEND    : { break; }

            case CPROGBEGIN  : { break; }

          } /* switch */
          j++;
          } /* if */
       } /* while */

       /* imprime tabela de simbolos */
       fprintf(YYSAIDA,"\n");
       fprintf(YYSAIDA,"%4s%s\n"," ",
            "==========TABELA DE SIMBOLOS==========");
       fprintf(YYSAIDA,"%s%4s%s%4s%s%4s%s%4s%s\n","nome"," ","classe"," ",
             "tipotam"," ","endoff"," ","nivel");
       for (i = 1; i <= l-1; i++)
           fprintf(YYSAIDA,"%6s%4d%8d%12d%12d\n",ts[i].nome,ts[i].classe,
               ts[i].tipotam,ts[i].endoff,ts[i].nivel);
     } /* IMPRIMECODIGO */
